package com.bw.a2208_ivideo_dl

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import android.widget.TextView
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.bw.lib_base.cons.RouterConst

class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        val splashIv  = findViewById<ImageView>(R.id.splash_iv)
        val countdown = findViewById<TextView>(R.id.countdown)
        Glide.with(this).load(com.bw.lib_res.R.drawable.welcome).into(splashIv)

        val animator = ValueAnimator.ofInt(5, 0).apply {
            this.duration = 5000L
            interpolator = LinearInterpolator()

            addUpdateListener { animation ->
                val currentValue = animation.animatedValue as Int
                countdown.text = currentValue.toString()

            }

            addListener(object : AnimatorListenerAdapter() {
                override fun onAnimationEnd(animation: Animator) {
                    ARouter.getInstance().build(RouterConst.PATH_MAIN_ACTIVITY).navigation()
                }
            })
        }
        animator.start()
    }
}